<?php
/*admin
* creates a list of modules to populate the admin panel with.
* @return modules
*/ 
function admin()
{
    $CI =& get_instance();
    if($CI->quickauth->logged_in())
    {
        // open the current directory
        $dhandle = opendir('modules');
        // define an array to hold the files
        $files = array();

        if ($dhandle)
        {
            // loop through all of the files
            while (false !== ($fname = readdir($dhandle)))
            {
                // if the file is not this file, and does not start with a '.' or '..',
                // then store it for later display
                if ($fname[0] != '.')
                {
                  // store the filename
                  $files[] = (is_dir( "./$fname" )) ? "(Dir) {$fname}" : $fname;
              }
           }
           // close the directory
           closedir($dhandle);
        }

        // Now loop through the files, echoing out a new select option for each one
        foreach( $files as $fname )
        {
			$name = $CI->functions->capitalize( $CI->functions->underscore2space( $fname ) );
			if( file_exists('./modules/'.$fname.'/back.txt') )				
			{
            	echo("<li class='nav-$fname'>".anchor($fname.'/admin/', $name."")."</li>\n");
			}
        } // foreach
    }
} // admin()


function admin_pages()
{
	echo("
		<ul>
			<li>".anchor('pages/admin', 'Manage Pages')."</li>
			<li>".anchor('pages/admin/add', 'Add a Page')."</li>
		</ul>
	");
}

function admin_users()
{
	echo("
		<ul>
			<li>".anchor('user/admin', 'Manage Users')."</li>
			<li>".anchor('user/admin/add', 'Add a User')."</li>
		</ul>
	");
}

function admin_downloads()
{
	echo("
		<ul>
			<li>".anchor('download/admin', 'Manage Downloads')."</li>
			<li>".anchor('download/admin/upload', 'Upload File')."</li>
		</ul>
	");
}


function front_nav()
{
    $CI =& get_instance();
    $CI->load->model('mdl_nav_helper');
	echo("<ul>"); // Open the navigation
		foreach( $CI->mdl_nav_helper->get_navigation() As $nav )
		{
				$li_class = preg_replace('/\s\s*/', '_', $nav['title']); // Turn "Example Text" in to "Example_Text" for styling purpose
				echo("<li class=".$li_class.">".anchor($nav['fake_route'], $nav['title'])."</li>\n"); // Put a top level navigation item on the screen
		}
}

// end of nav helper
